package man4j;

import javax.microedition.lcdui.Image;

public class ImageUtils {
	public static Image resizeImage(Image image, int resizedWidth, int resizedHeight) {  
		int[] in = null, out = null;

		int width = image.getWidth(), height = image.getHeight();
		
		in = new int[width];

		int dy, dx;
		
		out = new int[resizedWidth * resizedHeight];

		for (int y = 0; y < resizedHeight; y++) {
			dy = y * height / resizedHeight;

			image.getRGB(in, 0, width, 0, dy, width, 1);

			for (int x = 0; x < resizedWidth; x++) {
				dx = x * width / resizedWidth;

				out[(resizedWidth * y) + x] = in[dx];
			}
		}
		
		Image resized = Image.createRGBImage(out, resizedWidth, resizedHeight, true);
		
		return resized;
	}  
}
